package com.ruoyi.nongjt.service.impl;

import com.ruoyi.common.core.domain.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.core.page.PageUtils;
import com.ruoyi.nongjt.domain.NjtInspectionRecord;
import com.ruoyi.nongjt.mapper.NjtInspectionRecordMapper;
import com.ruoyi.nongjt.service.NjtInspectionRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author L
 * @version 1.0
 * @date 2025/9/26 13:32
 * @see http://baidu.com
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class NjtInspectionRecordServiceImpl implements NjtInspectionRecordService {

    @Autowired
    private NjtInspectionRecordMapper inspectionRecordMapper;

    @Override
    public TableDataInfo selectNjtInspectionRecordPage(NjtInspectionRecord inspectionRecord) {
        // 只需要调用 startPage() 开启分页，不需要传递任何参数
        PageUtils.startPage();
        // 调用 Mapper 方法查询列表（无需手动处理分页参数）
        List<NjtInspectionRecord> list = inspectionRecordMapper.selectNjtInspectionRecordList(inspectionRecord);
        // 用 PageUtils 构建分页结果
        return PageUtils.buildDataInfo(list);
    }

    @Override
    public List<NjtInspectionRecord> selectNjtInspectionRecordList(NjtInspectionRecord inspectionRecord) {
        return inspectionRecordMapper.selectNjtInspectionRecordList(inspectionRecord);
    }

    @Override
    public int insertNjtInspectionRecord(NjtInspectionRecord inspectionRecord) {
        inspectionRecord.setCreateBy(SecurityUtils.getUsername());
        inspectionRecord.setCreateTime(new Date());
        inspectionRecord.setDelFlag(0);
        return inspectionRecordMapper.insertNjtInspectionRecord(inspectionRecord);
    }

    @Override
    public int updateNjtInspectionRecord(NjtInspectionRecord inspectionRecord) {
        inspectionRecord.setUpdateBy(SecurityUtils.getUsername());
        inspectionRecord.setUpdateTime(new Date());
        return inspectionRecordMapper.updateNjtInspectionRecord(inspectionRecord);
    }

    @Override
    public int deleteNjtInspectionRecordById(Long id) {
        return inspectionRecordMapper.deleteNjtInspectionRecordById(id);
    }

    @Override
    public int deleteNjtInspectionRecordByIds(Long[] ids) {
        return inspectionRecordMapper.deleteNjtInspectionRecordByIds(ids);
    }

    @Override
    public NjtInspectionRecord selectNjtInspectionRecordById(Long id) {
        return inspectionRecordMapper.selectNjtInspectionRecordById(id);
    }
}